<?php

/**
 * PhotoModule actions.
 *
 * @package    ieasy
 * @subpackage PhotoModule
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class albumActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
    public function executeList(sfWebRequest $request)
    {
        $this->catalogId=$request->getParameter('catalogId');
        $this->recordCount=$request->getParameter('recordCount');
        $this->currentPage=$request->getParameter('currentPage');
        $this->link=$request->getParameter('link');
        if(null==$this->catalogId&&""==$this->catalogId)
            $this->catalogId=1000;
        if(null==$this->recordCount||""==$this->recordCount)
            $this->recordCount=42;//42
        if(null==$this->currentPage||""==$this->currentPage)
            $this->currentPage=1;
        if(null==$this->link||""==$this->link)
            $this->link=1;
        $catalogs = Doctrine_Core::getTable("Catalog")
              ->createQuery()
              ->where("catalog_id=?",$this->catalogId)
              ->execute();
      foreach($catalogs as $catalog)
      {
          $this->response->setTitle("美图_".$catalog->getDescription()."_".sfConfig::get("app_site_name")) ;
          break;
      }
        $query = Doctrine_Query::create()->from("PhotoGroup p")
                ->Where('catalog_id='.$this->catalogId)->andWhere('p.status_id=1005');
        if(null!=$this->link&&""!=$this->link&& 1!=$this->link)
            $query=$query->andWhere("capital_letter='".$this->link."'");
        $query=$query->orderBy('p.modify_time desc,p.photo_group_id desc');
        $this->pages = new sfDoctrinePager('PhotoGroup',$this->recordCount);//$this->currentPage
        $this->pages->setQuery($query);  //$q   数据库查询语句
        $this->pages->setPage($this->currentPage);//
        $this->pages->init();
    }

    public function executeDetail(sfWebRequest $request)
    {
        $this->photoGroupId=$request->getParameter('photoGroupId');

        $this->order=$request->getParameter('order');
        if(null==$this->order||""==$this->order)
            $this->order=1;
        if(null==$this->photoGroupId||""==$this->photoGroupId)
            $this->photoGroupId=1003;
        $photoGroups = Doctrine_Core::getTable("PhotoGroup")
                ->createQuery()
                ->where("photo_group_id=?",$this->photoGroupId)
                ->execute();
        $this->catalogId = null;
        foreach($photoGroups as $photoGroup)
        {
             $this->title=$photoGroup->getTitle();
             $this->catalogId = $photoGroup->getCatalogId();
             $this->response->setTitle($photoGroup->getTitle()."_美图_".$photoGroup->getCatalog()->getDescription()."_".sfConfig::get("app_site_name")) ;
             $this->response->setKeywords($photoGroup->getKeyword()) ;
             break;
        }
        $execsql=Doctrine_Core::getTable("photo")->createQuery('p')
                ->where("photo_group_id='".$this->photoGroupId."'")
                ->orderBy('p.order_i asc');
        $this->photos=$execsql->execute() ;
        
        /*if(null==$celebrityid||""==$celebrityid)
            $celebrityid=1000;
        $execsql=Doctrine_Core::getTable("celebrity")->createQuery('c')->where("celebrity_id='".$celebrityid."'");
        $catalogid= $request->getParameter('catalogId');
        if(null==$catalogid||""==$catalogid)
            $catalogid=1000;
        $execsql=$execsql->andWhere("catalog_id='".$catalogid."'");
        $this->celebritys=$execsql->execute() ;*/

        
        /*$this->userName = $this->getUser()->getAttribute('userName', '');
        $this->userId = $this->getUser()->getAttribute('userId', '1000');
        $this->homeuser_id=$request->getParameter("homeuser_id");
        if(!empty($_GET["photo_group_id"]))
        {
            $this->jjj=$_GET["photo_group_id"];
        }
        if(!empty($_POST["user_id"])&&!empty($_POST["photo_id"])&&!empty($_POST["comtext"]))
        {
            $_POST['user_id']=1000;
            $sqlStr="insert into Comment(comment_id,user_id,body) values ('8','".$_POST['user_id']."','".$_POST['comtext']."')";
            $connection = Doctrine_Manager::connection();
            $STH=$connection->execute($sqlStr);
            if($STH){}
        }*/

        
    }

    public function executeAddcomment(sfWebRequest $request)
    {
        if(!empty($_POST["user_id"])&&!empty($_POST["photo_id"])&&!empty($_POST["comtext"]))
        {
            if(empty($_POST["contentTypeId"]))
                $_POST["contentTypeId"]=1003;
            $sqlStr="insert into Comment(content_id,user_id,body,content_type_i,create_time,modify_time) values ('".$_POST["photo_id"]."','".$_POST["user_id"]."','".$_POST["comtext"]."','".$_POST["contentTypeId"]."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
            $connection = Doctrine_Manager::connection();
            $STH=$connection->execute($sqlStr);
            if($STH){
                $this->iscomment=1;
            }
        }
        if($request->isXmlHttpRequest())
        {
            return $this->renderComponent('user','commentlist',array("contentId"=>$_POST["photo_id"],"contentTypeId"=>$_POST["contentTypeId"]));
        }
    }
}
